package com.mobilesalon.model;

import java.text.ParseException;
import java.util.Calendar;

import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

import com.mobilesalon.tools.DateTools;

public class AppointmentBean implements Parcelable {
	private static final String TAG = AppointmentBean.class.getName();

	private long id;
	private String clientLookupKey;
	private String clientDisplayName;
	private long calendarId;
	private String calendarOwner;
	private Calendar date;
	private String location;
	private boolean IsStored;
	private float price;

	public AppointmentBean() {
		super();
	}

	public AppointmentBean(long id, String clientLookupKey, String clientDisplayName,
			long calendarId, String calendarOwner, Calendar date, String location,
			boolean isStored, float price) {
		super();
		this.id = id;
		this.clientLookupKey = clientLookupKey;
		this.clientDisplayName = clientDisplayName;
		this.calendarId = calendarId;
		this.calendarOwner = calendarOwner;
		this.date = date;
		this.location = location;
		this.IsStored = isStored;
		this.price = price;
	}

	public float getPrice() {
		return price;
	}

	public void setPrice(float price) {
		this.price = price;
	}

	public long getId() {
		return id;
	}

	public String getClientLookupKey() {
		return clientLookupKey;
	}

	public String getClientDisplayName() {
		return clientDisplayName;
	}

	public Calendar getDate() {
		return date;
	}

	public String getLocation() {
		return location;
	}

	public int describeContents() {
		return 0;
	}

	public void setId(long id) {
		this.id = id;
	}

	public void setClientLookupKey(String clientLookupKey) {
		this.clientLookupKey = clientLookupKey;
	}

	public void setClientDisplayName(String clientDisplayName) {
		this.clientDisplayName = clientDisplayName;
	}

	public void setDate(Calendar date) {
		this.date = date;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public boolean isIsStored() {
		return IsStored;
	}

	public void setIsStored(boolean isStored) {
		IsStored = isStored;
	}

	public long getCalendarId() {
		return calendarId;
	}

	public void setCalendarId(long calendarId) {
		this.calendarId = calendarId;
	}

	public String getCalendarOwner() {
		return calendarOwner;
	}

	public void setCalendarOwner(String calendarOwner) {
		this.calendarOwner = calendarOwner;
	}

	public void writeToParcel(Parcel out, int flags) {
		out.writeLong(id);
		out.writeString(clientLookupKey);
		out.writeString(clientDisplayName);
		out.writeLong(calendarId);
		out.writeString(calendarOwner);
		out.writeString(DateTools.TIMESTAMP_DATEFORMAT.format(date.getTime()));
		out.writeString(location);
		out.writeInt(IsStored ? 1 : 0);
		out.writeFloat(price);

	}

	public static final Parcelable.Creator<AppointmentBean> CREATOR = new Parcelable.Creator<AppointmentBean>() {
		public AppointmentBean createFromParcel(Parcel in) {
			return new AppointmentBean(in);
		}

		public AppointmentBean[] newArray(int size) {
			return new AppointmentBean[size];
		}
	};

	private AppointmentBean(Parcel in) {
		id = in.readLong();

		clientLookupKey = in.readString();

		clientDisplayName = in.readString();

		calendarId = in.readLong();

		calendarOwner = in.readString();

		Calendar dateLocal = Calendar.getInstance();
		String dateStringLocal = in.readString();
		try {
			dateLocal.setTime(DateTools.TIMESTAMP_DATEFORMAT.parse(dateStringLocal));
		} catch (ParseException e) {
			Log.e(TAG, "Cannot parse datetime:" + dateStringLocal);
			e.printStackTrace();
		}
		this.date = dateLocal;

		location = in.readString();

		IsStored = in.readInt() == 0 ? false : true;

		price = in.readFloat();
	}
}
